import random


class QuestionData ():

    def __init__(self) -> None:
        self.questions = [[],[]]

    
    def AddQuestion (self,identiy,question,choice,qtype): #新建问题，第一个选项为正确答案
        new_question = {'Question':question,'Choice':choice,'Type':qtype}
        self.questions[identiy].append(new_question)

    
    def RandomExtract (self,identity): #随机抽取问题
        if len (self.questions[1-identity]) <= 0:
            return -1 #用户还未构建问题

        return random.randint (0,len (self.questions[1-identity])-1)

    
    def ShowQuestion (self,identity,qid): #返回问题
        if qid < 0:
            return ''
        
        else:
            return self.questions[1-identity][qid]


    def Judger (self,answer,qid,identity): #答案判定
        if answer == self.questions[1-identity][qid]['Choice'][0]:
            return 1
        else:
            return 0